package com.example.denglu.util;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SessionManager {
    private static final Map<String, Map<String, Object>> sessionMap = new ConcurrentHashMap<>();
    private static final Map<String, String> openidSceneMap = new ConcurrentHashMap<>();
    
    public static void setAttribute(String sceneStr, String key, Object value) {
        sessionMap.computeIfAbsent(sceneStr, k -> new ConcurrentHashMap<>()).put(key, value);
    }
    
    public static Object getAttribute(String sceneStr, String key) {
        Map<String, Object> session = sessionMap.get(sceneStr);
        return session != null ? session.get(key) : null;
    }
    
    public static void removeAttribute(String sceneStr, String key) {
        Map<String, Object> session = sessionMap.get(sceneStr);
        if (session != null) {
            session.remove(key);
        }
    }
    
    public static void removeSession(String sceneStr) {
        sessionMap.remove(sceneStr);
    }
    
    public static void saveSceneStrForOpenid(String openid, String sceneStr) {
        openidSceneMap.put(openid, sceneStr);
    }
    
    public static String getSceneStrByOpenid(String openid) {
        return openidSceneMap.get(openid);
    }
    
    public static void removeSceneStrForOpenid(String openid) {
        openidSceneMap.remove(openid);
    }
} 